package com.jin.flashsaled.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {
    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        //获取模板
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        //设置key序列化
        template.setKeySerializer(new StringRedisSerializer());
        //设置value序列化
        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        //设置hashkey序列化
        template.setHashKeySerializer(new StringRedisSerializer());
        //设置hashvalue序列化
        template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
        //注入连接工场
        template.setConnectionFactory(redisConnectionFactory);



        return template;
    }
}

